# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=haskell-gi
pkgname=haskell-gi
pkgver=0.26.4
pkgrel=43
pkgdesc="Generate Haskell bindings for GObject Introspection capable libraries"
url="https://github.com/haskell-gi/haskell-gi"
license=("LGPL2")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'glib2' 'gobject-introspection-runtime' 'haskell-gi-base'
         'haskell-ansi-terminal' 'haskell-attoparsec' 'haskell-pretty-show' 'haskell-safe'
         'haskell-xdg-basedir' 'haskell-xml-conduit' 'haskell-regex-tdfa')
makedepends=('ghc' 'gobject-introspection' 'haskell-cabal-doctest' 'haskell-doctest')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('c5a34576cfe2df07d4c1a9c01f925680f1dd57d483a62d85c6d6fcc0f852ada1bd00c25e805dca8498f6b663a88d5c9daf696bce99664bd65f111d226927c6af')

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
